package com.lsa.helpers;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

public class IntArrayListAdapter implements List<Integer>
{	
	private int[] array;
	
	public IntArrayListAdapter(int[] array)
	{
		this.array = array;
	}
	
	public static IntArrayListAdapter adapt(int[] array)
	{
		return new IntArrayListAdapter(array);
	}

	public boolean add(Integer e)
	{
		throw new NotImplementedException();
	}

	@Override
	public void add(int index, Integer element)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean addAll(Collection<? extends Integer> c)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean addAll(int index, Collection<? extends Integer> c)
	{
		throw new NotImplementedException();
	}

	@Override
	public void clear()
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean contains(Object o)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean containsAll(Collection<?> c)
	{
		throw new NotImplementedException();
	}

	@Override
	public Integer get(int i)
	{
		return Integer.valueOf(this.array[i]);
	}

	@Override
	public int indexOf(Object o)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean isEmpty()
	{
		return this.array.length == 0;
	}

	@Override
	public Iterator<Integer> iterator()
	{
		return new InnerListIterator();
	}

	@Override
	public int lastIndexOf(Object o)
	{
		throw new NotImplementedException();
	}
	
	private class InnerListIterator implements  ListIterator<Integer> 
	{
		int i = -1;
		
		@Override
		public boolean hasNext()
		{
			return i != array.length - 1;
		}

		@Override
		public Integer next()
		{
			return Integer.valueOf(array[++i]);
		}

		@Override
		public void remove()
		{
			throw new NotImplementedException();
		}

		@Override
		public void add(Integer e)
		{
			throw new NotImplementedException();
		}

		@Override
		public boolean hasPrevious()
		{
			return i > 0;
		}

		@Override
		public int nextIndex()
		{
			return i + 1;
		}

		@Override
		public Integer previous()
		{
			return Integer.valueOf(array[--i]);
		}

		@Override
		public int previousIndex()
		{
			return i - 1;
		}

		@Override
		public void set(Integer e)
		{
			array[i] = e.intValue();
		}
	}

	@Override
	public ListIterator<Integer> listIterator()
	{
		return new InnerListIterator();
	}

	@Override
	public ListIterator<Integer> listIterator(int index)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean remove(Object o)
	{
		throw new NotImplementedException();
	}

	@Override
	public Integer remove(int index)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean removeAll(Collection<?> c)
	{
		throw new NotImplementedException();
	}

	@Override
	public boolean retainAll(Collection<?> c)
	{
		throw new NotImplementedException();
	}

	@Override
	public Integer set(int index, Integer element)
	{
		return this.array[index] = element.intValue();
	}

	@Override
	public int size()
	{
		return this.array.length;
	}

	@Override
	public List<Integer> subList(int fromIndex, int toIndex)
	{
		throw new NotImplementedException();
	}

	@Override
	public Object[] toArray()
	{
		Object[] objArray = new Object[array.length];
		for (int i = 0; i < array.length; i++)
		{
			objArray[i] = Integer.valueOf(array[i]);
		}
		
		return objArray;
	}

	@Override
	public <T> T[] toArray(T[] a)
	{
		throw new NotImplementedException();
	}
}
